﻿using MediatR;
using RBAC.Common.Domains.RabbitProject;
using RBAC.Common.Dto;
using RBAC.Common.infrastructures.interfaces;
using RBAC.Enum;

namespace RBAC.api.Application.commond.Slaughter
{
    public class RelevantqualifiedenterprisesHander : IRequestHandler<RelevantqualifiedenterprisesCommond, Rulst>
    {

        private readonly IbaseRpository<ProductionPutImages> _ProductionPutImages;

        public RelevantqualifiedenterprisesHander(IbaseRpository<ProductionPutImages> productionPutImages)
        {
            _ProductionPutImages = productionPutImages;
        }

        public async Task<Rulst> Handle(RelevantqualifiedenterprisesCommond request, CancellationToken cancellationToken)
        {
            var query = new Rulst() { Code = (int)Reult.success };


            var list = _ProductionPutImages.Query().Where(x => x.ProDuctionBasicid == request.ProDuctionBasicid && x.Stypeid== Typenum.屠宰企业).ToList();
           

            if(list.Count<6)
            {
                var result = new ProductionPutImages()
                {
                    Stypeid = Typenum.屠宰企业,
                    ProDuctionBasicid = request.ProDuctionBasicid,
                    Putid = 0,
                    PutImages = request.iamges,
                };


                query.data = _ProductionPutImages.Add(result);

                query.MSG = "添加成功";
            }
            else
            {
                query.data = -7;
            }
           

            return query;



        }
    }
}
